package org.glut.controller;

import org.glut.bean.GZ;
import org.glut.service.GZService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
/**
 * 光照度
 * @author 啊林
 * @date 2022/1/10
 * @time 0:05
 */
public class GZController {
    @Autowired
    private GZService gzService;

    @RequestMapping("/gzline")
    public String gzline(){
        return "/myviews/gzline";
    }

    @RequestMapping("/gzpower")
    public String gzpower(){
        return "/myviews/gzpower";
    }

    /**
     * 获取光照度bean
     * @return
     */
    @RequestMapping("/getGZ")
    @ResponseBody
    public GZ getGZ(String id) {
        if ("1".equals(id)) {
            return GZService.gz1;
        }else{
            return GZService.gz2;
        }
    }

    /**
     * 发命令控制光照度
     * @return
     */
    @RequestMapping("/sendGZ")
    @ResponseBody
    public boolean sendGZ(String num,String auto,String status,String id) {
        gzService.setCmd(num,auto,status,id);
        return true;
    }

    /**
     * 获取光照度上传时间List
     * @return
     */
    @RequestMapping("/getgzTimeDate")
    @ResponseBody
    public List<String> getgzTimeDate(String id){
        List<String> timeList;
        if ("1".equals(id)) {
            timeList = gzService.gztimeList1;
        }else {
            timeList = gzService.gztimeList2;
        }
        if (timeList.size() > 30) {
//            List<String> list = timeList.subList(timeList.size() - 30, timeList.size() - 1);
//            gzService.timeList.remove(0);
//            gzService.timeList = new ArrayList<>(list);
            timeList.remove(0);
        }
        return timeList;
    }

    /**
     * 获取光照度上传浓度List
     * @return
     */
    @RequestMapping("/getgzNumDate")
    @ResponseBody
    public List<String> getgzNumDate(String id){
        List<String> gzList ;
        if ("1".equals(id)) {
            gzList = gzService.gznumList1;
        }else {
            gzList = gzService.gznumList2;
        }
        if (gzList.size() > 30) {
//                List<String> list = gzList.subList(gzList.size() - 30, gzList.size() - 1);
//                gzService.gzList = new ArrayList<>(list);
            int size = gzList.size();
            gzList = gzList.subList(size-30,size);
        }
        return gzList;
    }

    /**
     * 获取光照度上传电量List
     * @return
     */
    @RequestMapping("/getgzpowerDate")
    @ResponseBody
    public List<String> getgzpowerDate(String id){
        List<String> gzList;
        if ("1".equals(id)) {
            gzList = gzService.gzpower1;
        }else {
            gzList = gzService.gzpower2;
        }
        if (gzList.size() > 30) {
//                List<String> list = gzList.subList(gzList.size() - 30, gzList.size() - 1);
//                gzService.gzList = new ArrayList<>(list);
            int size = gzList.size();
            gzList = gzList.subList(size-30,size);
        }
        return gzList;
    }

}
